﻿namespace ACCOUNTING
{
    using ACCOUNTING.LVY.Business;
    using ACCOUNTING.My.Resources;
    using Microsoft.VisualBasic;
    using Microsoft.VisualBasic.CompilerServices;
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Diagnostics;
    using System.Drawing;
    using System.Runtime.CompilerServices;
    using System.Windows.Forms;

    [DesignerGenerated]
    public class ADVObjects : UserControl
    {
        private static List<WeakReference> __ENCList = new List<WeakReference>();
        [AccessedThroughProperty("CmdShow")]
        private Button _CmdShow;
        [AccessedThroughProperty("TxtCode")]
        private TextBox _TxtCode;
        [AccessedThroughProperty("TxtName")]
        private TextBox _TxtName;
        private IContainer components;
        private string mConditions;
        private string mLoai;
        private modGeneral.TypeObjects mLoaiDoiTuong;
        private bool mReadOnly;
        private bool mUpperText;
        private string mValue;
        private int mWithCode;

        public event GotfocusEventHandler Gotfocus;

        public event KeyPressEventHandler KeyPress;

        public event LostFocusEventHandler LostFocus;

        public event ValueChangedEventHandler ValueChanged;

        public ADVObjects()
        {
            this.Gotfocus += new GotfocusEventHandler(this.ADVList_Gotfocus);
            base.PreviewKeyDown += new PreviewKeyDownEventHandler(this.ADVObjects_PreviewKeyDown);
            base.Resize += new EventHandler(this.ADVList_Resize);
            List<WeakReference> list = __ENCList;
            lock (list)
            {
                __ENCList.Add(new WeakReference(this));
            }
            this.mValue = "";
            this.mWithCode = 80;
            this.mUpperText = true;
            this.mReadOnly = false;
            this.mConditions = "";
            this.InitializeComponent();
        }

        private void ADVList_Gotfocus(object sender, EventArgs e)
        {
            this.TxtCode.Focus();
        }

        private void ADVList_Resize(object sender, EventArgs e)
        {
            this.Height = this.TxtCode.Height;
            this.CmdShow.Left = (this.TxtName.Right - this.CmdShow.Width) - 2;
        }

        private void ADVObjects_PreviewKeyDown(object sender, PreviewKeyDownEventArgs e)
        {
            if (e.KeyCode == Keys.Tab)
            {
                this.GetValue();
            }
        }

        private void CmdShow_Click(object sender, EventArgs e)
        {
            if (!this.mReadOnly)
            {
                string pValue = SearchModule.SearchDoiTuong("", LVYModule.ReturnIfNull(this.mLoai, "", modGeneral.TypeOfValue.Nothing).ToString(), this.mConditions);
                if (LVYModule.ReturnIfNull(pValue, "", modGeneral.TypeOfValue.Nothing).ToString().Trim() != "")
                {
                    object instance = Strings.Split(pValue, "|", -1, CompareMethod.Binary);
                    if ((Information.UBound((Array) instance, 1) == 2) && (NewLateBinding.LateIndexGet(instance, new object[] { 0 }, null).ToString() != this.mValue.Trim()))
                    {
                        this.TxtCode.Text = Conversions.ToString(NewLateBinding.LateIndexGet(instance, new object[] { 1 }, null));
                        this.TxtName.Text = Conversions.ToString(NewLateBinding.LateIndexGet(instance, new object[] { 2 }, null));
                        this.TxtCode.Tag = RuntimeHelpers.GetObjectValue(NewLateBinding.LateIndexGet(instance, new object[] { 1 }, null));
                        this.mValue = Conversions.ToString(NewLateBinding.LateIndexGet(instance, new object[] { 0 }, null));
                        ValueChangedEventHandler valueChangedEvent = this.ValueChanged;
                        if (valueChangedEvent != null)
                        {
                            valueChangedEvent(this, null);
                        }
                    }
                }
                else if (this.mValue.Trim() == "")
                {
                    this.TxtCode.Text = "";
                    this.TxtName.Text = "";
                    this.TxtCode.Tag = "";
                    this.mValue = "";
                }
            }
        }

        private void CmdShow_GotFocus(object sender, EventArgs e)
        {
            this.TxtCode.Focus();
        }

        private void CmdShow_MouseLeave(object sender, EventArgs e)
        {
            if (!this.mReadOnly)
            {
                this.CmdShow.BackgroundImage = ACCOUNTING.My.Resources.Resources.ButtonLight;
            }
        }

        private void CmdShow_MouseMove(object sender, MouseEventArgs e)
        {
            if (!this.mReadOnly)
            {
                this.CmdShow.BackgroundImage = ACCOUNTING.My.Resources.Resources.ButtonActive;
            }
        }

        [DebuggerNonUserCode]
        protected override void Dispose(bool disposing)
        {
            if (disposing && (this.components != null))
            {
                this.components.Dispose();
            }
            base.Dispose(disposing);
        }

        private void GetValue()
        {
            if (!this.mReadOnly)
            {
                ValueChangedEventHandler valueChangedEvent;
                if (this.TxtCode.Text.Trim() == "")
                {
                    this.mValue = "";
                    this.TxtName.Text = "";
                    this.TxtCode.Tag = "";
                    if (this.mValue.Trim() != "")
                    {
                        valueChangedEvent = this.ValueChanged;
                        if (valueChangedEvent != null)
                        {
                            valueChangedEvent(this, null);
                        }
                    }
                    this.ParentForm.SelectNextControl(this, true, true, true, true);
                }
                else if (LVYModule.ReturnIfNull(this.TxtCode.Text, "", modGeneral.TypeOfValue.Nothing).ToString().Trim() == LVYModule.ReturnIfNull(RuntimeHelpers.GetObjectValue(this.TxtCode.Tag), "", modGeneral.TypeOfValue.Nothing).ToString().Trim())
                {
                    this.ParentForm.SelectNextControl(this, true, true, true, true);
                }
                else
                {
                    string pValue = SearchModule.SearchDoiTuong(this.TxtCode.Text, LVYModule.ReturnIfNull(this.mLoai, "", modGeneral.TypeOfValue.Nothing).ToString(), this.mConditions);
                    if (LVYModule.ReturnIfNull(pValue, "", modGeneral.TypeOfValue.Nothing).ToString().Trim() != "")
                    {
                        object instance = Strings.Split(pValue, "|", -1, CompareMethod.Binary);
                        if (Information.UBound((Array) instance, 1) == 2)
                        {
                            this.TxtCode.Text = Conversions.ToString(NewLateBinding.LateIndexGet(instance, new object[] { 1 }, null));
                            this.TxtName.Text = Conversions.ToString(NewLateBinding.LateIndexGet(instance, new object[] { 2 }, null));
                            this.TxtCode.Tag = RuntimeHelpers.GetObjectValue(NewLateBinding.LateIndexGet(instance, new object[] { 1 }, null));
                            if (Operators.ConditionalCompareObjectNotEqual(this.mValue, NewLateBinding.LateIndexGet(instance, new object[] { 0 }, null), false))
                            {
                                this.mValue = Conversions.ToString(NewLateBinding.LateIndexGet(instance, new object[] { 0 }, null));
                                valueChangedEvent = this.ValueChanged;
                                if (valueChangedEvent != null)
                                {
                                    valueChangedEvent(this, null);
                                }
                            }
                        }
                        this.ParentForm.SelectNextControl(this, true, true, true, true);
                    }
                    else if (this.mValue != "")
                    {
                        this.TxtCode.Text = LVYModule.ReturnIfNull(RuntimeHelpers.GetObjectValue(this.TxtCode.Tag), "", modGeneral.TypeOfValue.Nothing).ToString().Trim();
                    }
                }
            }
        }

        [DebuggerStepThrough]
        private void InitializeComponent()
        {
            this.TxtName = new TextBox();
            this.TxtCode = new TextBox();
            this.CmdShow = new Button();
            this.SuspendLayout();
            this.TxtName.Dock = DockStyle.Fill;
            Point point = new Point(80, 0);
            this.TxtName.Location = point;
            this.TxtName.Name = "TxtName";
            this.TxtName.ReadOnly = true;
            Size size = new Size(0xc5, 20);
            this.TxtName.Size = size;
            this.TxtName.TabIndex = 5;
            this.TxtCode.Dock = DockStyle.Left;
            point = new Point(0, 0);
            this.TxtCode.Location = point;
            this.TxtCode.Name = "TxtCode";
            size = new Size(80, 20);
            this.TxtCode.Size = size;
            this.TxtCode.TabIndex = 4;
            this.CmdShow.BackgroundImage = ACCOUNTING.My.Resources.Resources.ButtonLight;
            this.CmdShow.FlatAppearance.BorderSize = 0;
            this.CmdShow.FlatStyle = FlatStyle.Flat;
            this.CmdShow.Font = new Font("Microsoft Sans Serif", 8.25f, FontStyle.Bold, GraphicsUnit.Point, 0xa3);
            point = new Point(0x103, 2);
            this.CmdShow.Location = point;
            this.CmdShow.Name = "CmdShow";
            size = new Size(0x10, 0x10);
            this.CmdShow.Size = size;
            this.CmdShow.TabIndex = 6;
            this.CmdShow.UseVisualStyleBackColor = true;
            SizeF ef = new SizeF(6f, 13f);
            this.AutoScaleDimensions = ef;
            this.AutoScaleMode = AutoScaleMode.Font;
            this.Controls.Add(this.CmdShow);
            this.Controls.Add(this.TxtName);
            this.Controls.Add(this.TxtCode);
            this.Name = "ADVObjects";
            size = new Size(0x115, 0x15);
            this.Size = size;
            this.ResumeLayout(false);
            this.PerformLayout();
        }

        private void TxtCode_GotFocus(object sender, EventArgs e)
        {
            if (this.mReadOnly)
            {
                this.ParentForm.SelectNextControl(this, true, true, true, true);
            }
            else
            {
                this.TxtCode.Tag = this.TxtCode.Text;
            }
        }

        private void TxtCode_KeyDown(object sender, KeyEventArgs e)
        {
            if ((e.KeyCode == Keys.Return) | (e.KeyCode == Keys.Tab))
            {
                this.GetValue();
            }
            if (e.KeyCode == Keys.F4)
            {
                this.CmdShow_Click(RuntimeHelpers.GetObjectValue(sender), e);
            }
        }

        private void TxtCode_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (this.mUpperText)
            {
                e.KeyChar = Conversions.ToChar(e.KeyChar.ToString().ToUpper());
            }
        }

        private void TxtCode_Leave(object sender, EventArgs e)
        {
            if (LVYModule.ReturnIfNull(this.TxtCode.Text, "", modGeneral.TypeOfValue.Nothing).ToString().Trim() != LVYModule.ReturnIfNull(RuntimeHelpers.GetObjectValue(this.TxtCode.Tag), "", modGeneral.TypeOfValue.Nothing).ToString().Trim())
            {
                this.GetValue();
            }
            else if ((this.mValue.Trim() == "") & (this.TxtCode.Text.Trim() != ""))
            {
                this.GetValue();
            }
        }

        private void TxtName_GotFocus(object sender, EventArgs e)
        {
            this.ParentForm.SelectNextControl(this, true, true, true, true);
        }

        internal virtual Button CmdShow
        {
            [DebuggerNonUserCode]
            get
            {
                return this._CmdShow;
            }
            [MethodImpl(MethodImplOptions.Synchronized), DebuggerNonUserCode]
            set
            {
                MouseEventHandler handler = new MouseEventHandler(this.CmdShow_MouseMove);
                EventHandler handler2 = new EventHandler(this.CmdShow_Click);
                EventHandler handler3 = new EventHandler(this.CmdShow_MouseLeave);
                EventHandler handler4 = new EventHandler(this.CmdShow_GotFocus);
                if (this._CmdShow != null)
                {
                    this._CmdShow.MouseMove -= handler;
                    this._CmdShow.Click -= handler2;
                    this._CmdShow.MouseLeave -= handler3;
                    this._CmdShow.GotFocus -= handler4;
                }
                this._CmdShow = value;
                if (this._CmdShow != null)
                {
                    this._CmdShow.MouseMove += handler;
                    this._CmdShow.Click += handler2;
                    this._CmdShow.MouseLeave += handler3;
                    this._CmdShow.GotFocus += handler4;
                }
            }
        }

        public string Conditions
        {
            get
            {
                return this.mConditions;
            }
            set
            {
                this.mConditions = value;
            }
        }

        public modGeneral.TypeObjects LoaiDoiTuong
        {
            get
            {
                return this.mLoaiDoiTuong;
            }
            set
            {
                this.mLoaiDoiTuong = value;
                switch (((int) value))
                {
                    case 1:
                        this.mLoai = "S";
                        break;

                    case 2:
                        this.mLoai = "C";
                        break;

                    case 3:
                        this.mLoai = "E";
                        break;

                    case 4:
                        this.mLoai = "B";
                        break;
                }
            }
        }

        public bool ReadOnly
        {
            get
            {
                return this.mReadOnly;
            }
            set
            {
                this.mReadOnly = value;
                this.TxtCode.ReadOnly = value;
                this.CmdShow.Enabled = !value;
                if (value)
                {
                    this.CmdShow.BackgroundImage = ACCOUNTING.My.Resources.Resources.ButtonBlur;
                }
                else
                {
                    this.CmdShow.BackgroundImage = ACCOUNTING.My.Resources.Resources.ButtonLight;
                }
            }
        }

        internal virtual TextBox TxtCode
        {
            [DebuggerNonUserCode]
            get
            {
                return this._TxtCode;
            }
            [MethodImpl(MethodImplOptions.Synchronized), DebuggerNonUserCode]
            set
            {
                EventHandler handler = new EventHandler(this.TxtCode_Leave);
                System.Windows.Forms.KeyPressEventHandler handler2 = new System.Windows.Forms.KeyPressEventHandler(this.TxtCode_KeyPress);
                EventHandler handler3 = new EventHandler(this.TxtCode_GotFocus);
                KeyEventHandler handler4 = new KeyEventHandler(this.TxtCode_KeyDown);
                if (this._TxtCode != null)
                {
                    this._TxtCode.Leave -= handler;
                    this._TxtCode.KeyPress -= handler2;
                    this._TxtCode.GotFocus -= handler3;
                    this._TxtCode.KeyDown -= handler4;
                }
                this._TxtCode = value;
                if (this._TxtCode != null)
                {
                    this._TxtCode.Leave += handler;
                    this._TxtCode.KeyPress += handler2;
                    this._TxtCode.GotFocus += handler3;
                    this._TxtCode.KeyDown += handler4;
                }
            }
        }

        internal virtual TextBox TxtName
        {
            [DebuggerNonUserCode]
            get
            {
                return this._TxtName;
            }
            [MethodImpl(MethodImplOptions.Synchronized), DebuggerNonUserCode]
            set
            {
                EventHandler handler = new EventHandler(this.TxtName_GotFocus);
                if (this._TxtName != null)
                {
                    this._TxtName.GotFocus -= handler;
                }
                this._TxtName = value;
                if (this._TxtName != null)
                {
                    this._TxtName.GotFocus += handler;
                }
            }
        }

        public bool UpperText
        {
            get
            {
                return this.mUpperText;
            }
            set
            {
                this.mUpperText = value;
            }
        }

        public string Value
        {
            get
            {
                return this.mValue;
            }
            set
            {
                if (value.Trim() != this.mValue.Trim())
                {
                    this.mValue = value;
                    if (value == "")
                    {
                        this.TxtCode.Text = "";
                        this.TxtName.Text = "";
                    }
                    else
                    {
                        clsDMDoiTuong tuong = new clsDMDoiTuong();
                        tuong.Load(value);
                        this.TxtCode.Text = tuong.Ma;
                        if (modGeneral.H_LANGUAGE == "VIET")
                        {
                            this.TxtName.Text = tuong.TenViet;
                        }
                        else
                        {
                            this.TxtName.Text = tuong.TenAnh;
                        }
                        ValueChangedEventHandler valueChangedEvent = this.ValueChanged;
                        if (valueChangedEvent != null)
                        {
                            valueChangedEvent(this, null);
                        }
                    }
                }
            }
        }

        public int WidthCode
        {
            get
            {
                return this.mWithCode;
            }
            set
            {
                this.mWithCode = value;
                this.TxtCode.Width = value;
            }
        }

        public delegate void GotfocusEventHandler(object sender, EventArgs e);

        public delegate void KeyPressEventHandler(object sender, KeyPressEventArgs e);

        public delegate void LostFocusEventHandler(object sender, object Subsender, EventArgs e);

        public delegate void ValueChangedEventHandler(object sender, EventArgs e);
    }
}

